🎖️GitЯра🎖️
Node / meshtastic / Meshtastic-Android / files / app / src / main / java / com / geeksville / mesh / util / HardwareModelExtensions.kt
Displaying Raw • Download
app/src/main/java/com/geeksville/mesh/util/HardwareModelExtensions.kt ui_message_list (be3f882f) Text, 1.95 KB
T8b949e/*
* Copyright (c) 2025 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Tff7b72package T7ee787com.geeksville.mesh.util
Tff7b72import T7ee787com.geeksville.mesh.MeshProtos
Tff7b72import T7ee787com.geeksville.mesh.android.BuildUtils.warn
T8b949e/**
* Safely extracts the hardware model number from a HardwareModel enum.
*
* This function handles unknown enum values gracefully by catching IllegalArgumentException and returning a fallback
* value. This prevents crashes when the app receives data from devices with hardware models not yet defined in the
* current protobuf version.
*
* @param fallbackValue The value to return if the enum is unknown (defaults to 0 for UNSET)
* @return The hardware model number, or the fallback value if the enum is unknown
*/
Tf0883e@SuppressTb4b4b4(Ta5d6ff"Ta5d6ffdetekt:SwallowedExceptionTa5d6ff"Tb4b4b4)
Tff7b72fun Te6edf3MeshProtosTb4b4b4.Td2a8ffHardwareModelTb4b4b4.Te6edf3safeNumberTb4b4b4(Te6edf3fallbackValueTb4b4b4: Tffa657Int Tff7b72= Tff7b72-T79c0ff1Tb4b4b4)Tb4b4b4: Tffa657Int Tff7b72= Tff7b72try Tb4b4b4{
Tff7b72thisTb4b4b4.Te6edf3number
Tb4b4b4} Tff7b72catch Tb4b4b4(Te6edf3eTb4b4b4: Te6edf3IllegalArgumentExceptionTb4b4b4) Tb4b4b4{
Te6edf3warnTb4b4b4(Ta5d6ff"Ta5d6ffUnknown hardware model enum value: Tffd700$Te6edf3thisTa5d6ff, using fallback value: Tffd700$Te6edf3fallbackValueTa5d6ff"Tb4b4b4)
Te6edf3fallbackValue
Tb4b4b4}
T8b949e/**
* Checks if the hardware model is a known/supported value.
*
* @return true if the hardware model is known and supported, false otherwise
*/
Tf0883e@SuppressTb4b4b4(Ta5d6ff"Ta5d6ffdetekt:SwallowedExceptionTa5d6ff"Tb4b4b4)
Tff7b72fun Te6edf3MeshProtosTb4b4b4.Td2a8ffHardwareModelTb4b4b4.Te6edf3isKnownTb4b4b4(Tb4b4b4)Tb4b4b4: Tffa657Boolean Tff7b72= Tff7b72try Tb4b4b4{
Tff7b72thisTb4b4b4.Te6edf3number
Tff7b72true
Tb4b4b4} Tff7b72catch Tb4b4b4(Te6edf3eTb4b4b4: Te6edf3IllegalArgumentExceptionTb4b4b4) Tb4b4b4{
Tff7b72false
Tb4b4b4}
Served by rngit 1.5.0 - Generated in 0.08s